package design.adapter;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * <p>
 * media player impl
 * </P>
 *
 * @author dingwen
 * @date 2021.10.15 16:19
 */
public class MediaPlayerImpl implements MediaPlayer {

    public MediaPlayerImpl() {
    }

    /**
     * play
     *
     * @param audioType 音频类型
     * @param fileName  文件名称
     */
    @Override
    public void play(String audioType, String fileName) {
        Predicate<String> mp3Predicate = audioType::equalsIgnoreCase;
        if (mp3Predicate.test("mp3")) {
            System.out.println("mp3,MediaPlayerImpl");
        }else {
            adapterPlay(audioType, fileName);
        }
    }

    /**
     * 适配器播放
     *
     * @param audioType 音频类型
     * @param fileName  文件名称
     */
    public void adapterPlay(String audioType, String fileName) {

        Predicate<List<String>> advancedTypePredicate = typeList -> typeList.contains(audioType.toUpperCase());
        List<String> advancedTypeList = Arrays.asList("MP4", "VLC");
         if (advancedTypePredicate.test(advancedTypeList)) {
            new MediaAdapter(audioType).play(audioType, fileName);
        } else {
            System.out.println("invalid media. " + audioType + "format not supported");
        }
    }
}
